package com.nbsaas.boot;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.volcengine.ark.runtime.model.completion.chat.*;
import com.volcengine.ark.runtime.model.completion.chat.ChatCompletionRequest.*;
import com.volcengine.ark.runtime.service.ArkService;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.TimeUnit;
import okhttp3.ConnectionPool;
import okhttp3.Dispatcher;


public class Sample {
    //从环境变量中获取您的API KEY，配置方法见：https://www.volcengine.com/docs/82379/1399008
    static String apiKey = "abcbb0e3-8c35-4006-b7bd-7f553652f2e5";

    static ConnectionPool connectionPool = new ConnectionPool(5, 1, TimeUnit.SECONDS);
    static Dispatcher dispatcher = new Dispatcher();
    static ArkService service =
            ArkService.builder()
                    .dispatcher(dispatcher)
                    .connectionPool(connectionPool)
                    .apiKey(apiKey)
                    .build();

    public static void main(String[] args) throws JsonProcessingException {

        List<ChatMessage> messagesForReqList = new ArrayList<>();
        messagesForReqList.add(ChatMessage.builder().role(ChatMessageRole.SYSTEM).content("你是一个把ocr识别内容转换成json格式的程序，识别内容，返回josn格式，格式要求手机号，时长，时间").build());

        ChatMessage elementForMessagesForReqList0 =
                ChatMessage.builder()
                        .role(ChatMessageRole.USER)
                        .content("You are a helpful assistant.")
                        .build();
        messagesForReqList.add(elementForMessagesForReqList0);


        ChatCompletionRequest req =
                ChatCompletionRequest.builder()
                        .model("ep-20250615181650-gmg8x")
                        .messages(messagesForReqList)
                        .build();

        service.createChatCompletion(req)
                .getChoices()
                .forEach(choice -> System.out.println(choice.getMessage().getContent()));
        // shutdown service after all requests is finished
        service.shutdownExecutor();
    }
}
